package edu.washington.ling.syntric.io;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;

public class TreeFileWriterSGML extends TreeFileWriter {

	private PrintStream pStream;
	
	public TreeFileWriterSGML(String path) throws IOException {
		super(path);
		try {
			pStream = new PrintStream(new FileOutputStream(new File(path)), true, "UTF8");
		} 
		catch(UnsupportedEncodingException e) {
			pStream = new PrintStream(new FileOutputStream(new File(path)), true);
		}
	}
	
	@Override
	public void writeTreeRep(TreeRepresentation tr, String id) {
		pStream.println(String.format("<Sentence id=\"%s\">", id));
		for (String line: tr.getTreeLines()) {
			pStream.println(line);
		}
		pStream.println("</Sentence>\n");
	}

	@Override
	public void close() {
		pStream.close();
		
	}

}
